package com.atguigu.day08;

import org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend;
import org.apache.flink.contrib.streaming.state.RocksDBStateBackend;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.runtime.state.hashmap.HashMapStateBackend;
import org.apache.flink.runtime.state.memory.MemoryStateBackend;
import org.apache.flink.runtime.state.storage.FileSystemCheckpointStorage;
import org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.io.IOException;

public class Flink09_StateBackend {
    public static void main(String[] args) throws IOException {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //状态后端的设置
        //1.13之前的配置方式
        //内存
        env.setStateBackend(new MemoryStateBackend());

        //文件系统
        env.setStateBackend(new FsStateBackend("hdfs://hadoop102:8020/checkpoint"));

        //RockSDB
        env.setStateBackend(new RocksDBStateBackend("hdfs://hadoop102:8020/checkpoint"));


        //1.13之后的配置方式
        //内存
        env.setStateBackend(new HashMapStateBackend());
        env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());


        //文件系统
        env.setStateBackend(new HashMapStateBackend());
        env.getCheckpointConfig().setCheckpointStorage(new FileSystemCheckpointStorage("hdfs://hadoop102:8020/checkpoint"));
        //或者 但是上面写法可以设置更多的参数
        env.getCheckpointConfig().setCheckpointStorage("hdfs://hadoop102:8020/checkpoint");

        //RocksDB
        env.setStateBackend(new EmbeddedRocksDBStateBackend());
        env.getCheckpointConfig().setCheckpointStorage("hdfs://hadoop102:8020/checkpoint");
        env.getCheckpointConfig().setCheckpointStorage(new FileSystemCheckpointStorage("hdfs://hadoop102:8020/checkpoint"));
    }
}
